package com.study.a20youhuaMAX;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    private ArrayList<Integer> list;
    public MyCallable(ArrayList<Integer> list){
        this.list=list;
    }





    @Override
    public Integer call() throws Exception {
        ArrayList<Integer> boxList=new ArrayList<>();

        while(true){
            synchronized (MyCallable.class){
                if(list.isEmpty()){
                    System.out.println(Thread.currentThread().getName()+boxList);
                    break;

                }else{
                    Collections.shuffle(list);
                    int prize=list.remove(0);
                    boxList.add(prize);
                    //System.out.println(getName()+"产生"+prize+"奖金");
                }
            }

                Thread.sleep(10);




        }
        //把集合中最大值返回

        if(boxList.size()==0){
            return null;
        }else{
            return Collections.max(boxList);
        }


    }
}
